package priv.yiyuan.example.design.chain;

/**
 * 实现责任链的通用逻辑
 *
 * @author YiYuan
 * @data 2025/10/10
 * @apoNote
 */
public abstract class AbstractLoginCommand implements LoginCommand {

    protected LoginCommand nextCommand;

    @Override
    public void setNext(LoginCommand nextCommand) {
        this.nextCommand = nextCommand;
    }

    @Override
    public boolean execute(LoginContext context) {

        System.out.println("--- 执行命令: " + this.getClass().getSimpleName() + " ---");

        boolean result = this.process(context);

        if (!result) {
            System.out.println("❌ " + this.getClass().getSimpleName() + " 失败, 流程终止。");
            return false;
        }

        if (nextCommand != null) {
            return nextCommand.execute(context);
        }

        return true;
    }

    protected abstract boolean process(LoginContext context);
}
